package com.senjoeson.netlib;

import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;
import android.util.Log;

import org.junit.Test;
import org.junit.runner.RunWith;

import java.io.IOException;

import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;

/**
 * Instrumented test, which will execute on an Android device.
 *
 * @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
 */
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
    @Test
    public void useAppContext() throws Exception {
        // Context of the app under test.
        Context appContext = InstrumentationRegistry.getTargetContext();

        //assertEquals("com.senjoeson.netlib.test", appContext.getPackageName());

        OkHttpClient build = new OkHttpClient.Builder().build();


        Request.Builder builder = new Request.Builder();
        final Request request = builder.url("http://www.senjoeson.cn").get().build();
        build.newCall(request).enqueue(new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                Log.d("XXX"
                        , "onFailure: .");
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                Log.d("XXX",response.body().string());
                System.out.println(response.body().string());
            }
        });
    }
}
